<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<title>注册成功</title>
</head>
<body>
<%
//检测注册是否成功
	String userName = request.getParameter("userName");
	String psd = request.getParameter("psd");
	String phone = request.getParameter("phone");
	String url = "jdbc:mysql://localhost:3306/wacai?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8";
	Connection connection = null;
	PreparedStatement pstmt = null;
	String sql = null;
	
	if(userName!=null && psd!=null){
		try{
			Class.forName("com.mysql.jdbc.Driver");
		}catch(ClassNotFoundException exception){
			out.println("加载驱动器类时出现异常"+exception);
		}
		
		try{
			connection = DriverManager.getConnection(url,"root","root1234");//连接数据库
			sql = "insert into user values(?,?,?)";
			pstmt = connection.prepareStatement(sql);
			pstmt.setString(1,userName);
			pstmt.setString(2,psd);
			pstmt.setString(3,phone);
			pstmt.executeUpdate();
			pstmt.close();
			connection.close();
			out.print("<script type='text/javascript'>alert('注册成功');</script>");
			response.setHeader("Refresh","0.1;url=index.jsp");		
		%>
					
	<%	
		}catch(Exception e){
			out.print(e);
			//out.print("<script type='text/javascript'>alert('注册失败');</script>");
			//response.setHeader("Refresh","0.1;url=register.jsp");
		}}%>
</body>
</html>